const mongoose = require("mongoose");

const refreshTokenSchema = new mongoose.Schema(
    {
        user: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true, index: true },
        token: { type: String, required: true, unique: true, index: true },
        expiresAt: { type: Date, required: true, index: true },
        revoked: { type: Boolean, default: false, index: true },
    },
    { timestamps: true }
);

// 自动清理过期（可用 MongoDB TTL 索引，这里手动演示）
refreshTokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });

module.exports = mongoose.model("RefreshToken", refreshTokenSchema);
